package com.sg.service.biz.app.nb;

import cn.hutool.core.util.ObjectUtil;
import com.sg.common.util.CommonFunctionHelper;
import com.sg.dto.biz.app.req.ImplementPicMultipleSetDataEntryReqDto;
import com.sg.dto.biz.app.req.ImplementPicSingleSetDataEntryReqDto;
import com.sg.dto.biz.app.res.ImplementPicMultipleSetDataEntryRespDto;
import com.sg.dto.biz.app.res.ImplementPicSingleSetDataEntryRespDto;
import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author ： 手工接入方法
 * @version 1.0
 * @since 2022/5/28 15:32
 */
@Service
public class NbDataSetSingleEntry {
    /**
     * code:objectToData
     * name:M执行图片单条转数据集
     * desc:undefined
     * gen by moon at 11/29/2023, 9:31:49 PM
     **/
    @Trace(operationName = "M执行图片单条转数据集")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    public ImplementPicSingleSetDataEntryRespDto implementPicSingleSetDataEntry(ImplementPicSingleSetDataEntryReqDto reqDto) {
        ImplementPicSingleSetDataEntryRespDto retData = new ImplementPicSingleSetDataEntryRespDto();
        if (ObjectUtil.isEmpty(reqDto) || ObjectUtil.isEmpty(reqDto.getDatasetField())) {
            return retData;
        }
        String[] fileList = reqDto.getDatasetField().split(",");
        if (ObjectUtil.isEmpty(fileList)) {
            return retData;
        }
        List<String> retList = Arrays.asList(fileList);
        List<String> retNewList = new ArrayList<>();
        for (String one : retList) {
            if (one.equals("--")) {
                continue;
            }
            retNewList.add(CommonFunctionHelper.getFilePath(one));
        }
        retData.setPicSingleSetDataEntryList(retNewList);
        return retData;
    }

    /**
     * code:objectToData
     * name:M3执行图片多条转数据集
     * desc:undefined
     * gen by moon at 12/5/2023, 12:23:54 AM
     **/
    @Trace(operationName = "M3执行图片多条转数据集")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    public ImplementPicMultipleSetDataEntryRespDto implementPicMultipleSetDataEntry(ImplementPicMultipleSetDataEntryReqDto reqDto) {
        ImplementPicMultipleSetDataEntryRespDto retData = new ImplementPicMultipleSetDataEntryRespDto();
        for (PicMultipleSetDataEntryDto one : reqDto.getPicMultipleSetDataEntryList()) {
            String dataField = one.getDatasetField();
            List<String> dataList = Arrays.asList(dataField.split(","));
            for (String subOne : dataList) {
                if (subOne.equals("--")) {
                    continue;
                }
                PicMultipleSetDataEntryDto elm = new PicMultipleSetDataEntryDto();
                elm.setCycleStageDataId(one.getCycleStageDataId());
                elm.setDatasetField(CommonFunctionHelper.getFilePath(subOne));
                retData.getPicMultipleSetDataEntryList().add(elm);
            }
        }
        return retData;
    }
    //手工接入方法
}
